package baseinfo.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Nio {

    public static void copy(String fp,String cpFp) {
        try (
                FileInputStream fis = new FileInputStream(fp);
                FileChannel fc = fis.getChannel();
                FileOutputStream fos = new FileOutputStream(cpFp);
                FileChannel foc = fos.getChannel()
        ) {

            ByteBuffer buffer = ByteBuffer.allocate(1024);
            fc.read(buffer);
            buffer.flip();
            foc.write(buffer);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        copy("D:\\code\\leetcode\\src\\main\\java\\baseinfo\\io\\Nio.java","D:\\test.txt");
    }
}
